#include<bits/stdc++.h>
using namespace std;

const int N=1e6+5;

int t;
int n,m,l,vm;
int d[N],v[N],a[N],p[N];

inline int read(){
    int f=1,k=0;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-') f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        k=k*10+c-'0';
        c=getchar();
    }
    return f*k;
}

void A(){
    int maxn=0,ans=0;
    for(int i=1;i<=m;i++) maxn=max(maxn,p[i]);
    for(int i=1;i<=n;i++){
        if(d[i]<=maxn&&v[i]>vm) ans++;
    }
    cout<<ans<<" ";
    if(ans==0) cout<<m<<endl;
    else cout<<m-1<<endl;
}

/*
void B(){
    int car[N],cf[N];
    memset(cf,0,sizeof(cf));
    for(int i=1;i<=n;i++){
        if(v[i]>vm) car[i]=0;
        else if(a[i]==0) car[i]=(v[i]>vm ? l-d[i] : 0);
        else{
            int t=(vm-v[i])/a;
            if((vm-v[i])%a==0) t++;
            car[i]=
        }
    }
}
*/

int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    t=read();
    while(t--){
        n=read(),m=read(),l=read(),vm=read();
        int flag=0;
        for(int i=1;i<=n;i++){
            d[i]=read(),v[i]=read(),a[i]=read();
            if(a[i]!=0&&flag!=-1) flag=1;
            if(a[i]<0) flag=-1;
        }
        for(int i=1;i<=m;i++) p[i]=read();
        if(flag==0){
            A();
            continue;
        }
        /*
        if(flag==1){
            B();
            continue;
        }
        */
    }
    return 0;
}
